package com.ysm.freestyle.test.jetpack

import android.os.Bundle
import android.util.Log
import android.view.View
import androidx.databinding.DataBindingUtil
import androidx.lifecycle.MutableLiveData
import com.ysm.freestyle.R
import com.ysm.freestyle.base.BaseActivity
import com.ysm.freestyle.databinding.ActivityLiveBindingBinding

class LiveBindingActivity : BaseActivity() {

    private val mState = State()
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        val binding = DataBindingUtil.setContentView<ActivityLiveBindingBinding>(this,
            R.layout.activity_live_binding
        )
        binding.vm = mState
        binding.lifecycleOwner = this

        mState.name.observe(this){
            Log.i(TAG,"observe $it " )
        }

        mState.psw.observe(this){
            Log.i(TAG,"observe $it " )
        }
    }

    fun update(view: View){
        mState.name.value = mState.name.value + "->"
        mState.psw.value = mState.psw.value + "->"
    }

    class State{
        var name = MutableLiveData<String>("ysm")
        var psw = MutableLiveData<String>("123456")
    }
}